package com.yoda.youdianda.controller;

import com.yoda.youdianda.common.R;
import com.yoda.youdianda.dto.MenuDto;
import com.yoda.youdianda.service.SysMenuService;
import com.yoda.youdianda.vo.MenuDetailVo;
import com.yoda.youdianda.vo.MenuVo;
import com.yoda.youdianda.vo.WholeMenuVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author shawn
 * @date 2022年 11月 13日 21:03
 */

@RestController
@RequestMapping("/sys_menu")
public class SysMenuController {

    @Autowired
    private SysMenuService sysMenuService;

    @GetMapping("/allData")
    public R getAllMenu() {
        List<MenuDetailVo> voList = sysMenuService.getAllMenu();
        return R.success(voList);
    }

    /**
     * 根据菜单id得到菜单信息
     *
     * @param id 菜单id
     * @return {@link R}
     */
    @GetMapping("/rowInfo")
    public R getMenuInfo(String id) {
        MenuVo vo = sysMenuService.getMenuInfo(id);
        return R.success(vo);
    }

    /**
     * 插入菜单
     *
     * @param dto dto
     * @return {@link R}<{@link String}>
     */
    @PostMapping("add")
    public R<String> insertMenu(@RequestBody MenuDto dto) {
        return sysMenuService.insertMenu(dto);
    }


    /**
     * 删除菜单
     *
     * @param id 菜单id
     * @return {@link R}<{@link String}>
     */
    @GetMapping("/del")
    public R<String> deleteMenu(String id) {
        return sysMenuService.deleteMenu(id);
    }

    @PostMapping("/update")
    public R<String> updateMenu(@RequestBody MenuDto dto) {
        return sysMenuService.updateById(dto);
    }

}
